<!DOCTYPE html>
<html xmlns='http://www.w3.org/1999/xhtml' xmlns:th='http://www.thymeleaf.org'>

<body>
<span th:replace="@{banner}"></span>

<div class="container-fluid">
    <span th:replace="@{nav}"></span>

    <div class="wrapper">

        <div class="wrapper_header">
            <span th:if="${not #lists.isEmpty(departments)}">
                <span id="department_group" th:each="department,departmentStat:${departments}">
                    <span th:if="${departmentStat.index} eq 0">
                        <label><input name="department" type="radio" checked="checked"
                                      th:text="${department.name}"></label>
                    </span>
                    <span th:if="${departmentStat.index} ne 0">
                        <label><input name="department" type="radio" th:text="${department.name}"></label>
                    </span>
                </span>
            </span>
        </div>

        <ul class="menuOne_list" th:if="not ${#lists.isEmpty(allMenus)}">
                <span th:each="menuVO,menuVOStat : ${allMenus}">
                    <span th:if="${menuVO.menuOne} eq '首页'">
                        <li><h4 th:text="${menuVO.menuOne}"></h4></li>
                    </span>

                    <span th:if="${menuVO.menuOne} ne '首页'">
                        <li><h4 type="checkbox" th:text="${menuVO.menuOne}"></h4>
                            <ul class="menuTwo_list">
                            <span th:each="menuTwo,menuTwoStat : ${menuVO.menuTwo}">
                            <li th:if="${#lists.contains(customIds, menuTwo.id)}"><input th:data="${menuTwo.id}"
                                                                                         type="checkbox" checked
                                                                                         th:text="${menuTwo.menuTwo}"></li>
                            <li th:if="${not #lists.contains(customIds, menuTwo.id)}"><input type="checkbox"
                                                                                             th:data="${menuTwo.id}"
                                                                                             th:text="${menuTwo.menuTwo}"></li>
                            </span>
                            </ul>
                        </li>
                    </span>
                </span>
        </ul>

    </div>

</div>


<script type="text/javascript" th:src="@{/zs/assets/js/myModal.js}"></script>

<script>

    $('.system-nav li:eq(2)').addClass('choosed');

    $(function () {
        $('.menuTwo_list').each(function () {
            var $this = $(this);
            var childrens = $this.find('li');
            childrens.each(function () {
                var $this2 = $(this);
                $this2.bind('change', function () {
                    var department = $("#department_group input[name='department']:checked").parent().text();
                    var checkbox = $this2.find('input');
                    var url;
                    if (!checkbox.is(':checked')) {
                        url = '/zs/menu/del/' + department + '/' + checkbox.attr('data');
                        $.post(url, function (data, status) {
                            if (status == 'success') {
                            } else {
                                alert("删除失败");
                            }
                        });
                    }
                    else {
                        url = '/zs/menu/add/' + department + '/' + checkbox.attr('data');
                        $.post(url, function (data, status) {
                            if (status == 'success') {
                            } else {
                                alert("添加失败");
                            }
                        });
                    }
                });
            });


        });

    });

    $("#department_group input[name='department']").change(function () {
        var department = $(this).parent().text();
        var url = '/zs/menu/custom/' + department;
        $.post(url, function (data, status) {
            if (status == 'success') {
                $('.menuTwo_list').each(function () {
                    var $this = $(this);
                    var childrens = $this.find('li');
                    childrens.each(function () {
                        var $this2 = $(this);
                        $this2.find('input').removeAttr('checked');
                        $this2.find('input').each(function () {
                            if (data.contain($(this).attr('data')))
                                $(this).attr('checked', true);
                        })
                    });


                });
            }

        })
    });


</script>

</body>
</html>